


<!DOCTYPE html>
<html id="htmlId">
<head>
  <title>Coverage Report > Square</title>
  <style type="text/css">
    @import "../../css/coverage.css";
    @import "../../css/highlight-idea.css";
  </style>
  <script type="text/javascript" src="../../js/highlight.pack.js"></script>
</head>

<body>
<div class="content">
<div class="breadCrumbs">
Current scope:     <a href="../../index.html">all classes</a>
    <span class="separator">|</span>
    <a href="../index.html">nl.tudelft.jpacman.board</a>
</div>

<h1>Coverage Summary for Class: Square (nl.tudelft.jpacman.board)</h1>

<table class="coverageStats">

<tr>
  <th class="name">Class</th>
<th class="coverageStat 
">
  Method, %
</th>
<th class="coverageStat 
">
  Line, %
</th>
</tr>
<tr>
  <td class="name">Square</td>
<td class="coverageStat">
  <span class="percent">
    12.5%
  </span>
  <span class="absValue">
    (1/8)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    4.3%
  </span>
  <span class="absValue">
    (1/23)
  </span>
</td>
</tr>
  <tr>
    <td class="name">Square$MockitoMock$350497854</td>
  </tr>
  <tr>
    <td class="name">Square$MockitoMock$350497854$auxiliary$0ploGhm2</td>
  </tr>
  <tr>
    <td class="name">Square$MockitoMock$350497854$auxiliary$aFmtszTB</td>
  </tr>
  <tr>
    <td class="name">Square$MockitoMock$350497854$auxiliary$dSNrwZPG</td>
  </tr>
  <tr>
    <td class="name">Square$MockitoMock$350497854$auxiliary$GquxnQN2</td>
  </tr>
  <tr>
    <td class="name">Square$MockitoMock$350497854$auxiliary$S07BLyoQ</td>
  </tr>
  <tr>
    <td class="name">Square$MockitoMock$350497854$auxiliary$sbUhJpNk</td>
  </tr>
  <tr>
    <td class="name">Square$MockitoMock$350497854$auxiliary$U6CM4qG1</td>
  </tr>
<tr>
  <td class="name"><strong>Total</strong></td>
<td class="coverageStat">
  <span class="percent">
    12.5%
  </span>
  <span class="absValue">
    (1/8)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    4.3%
  </span>
  <span class="absValue">
    (1/23)
  </span>
</td>
</tr>
</table>

<br/>
<br/>


<pre>
<div class="sourceCode" id="sourceCode"><i class="no-highlight">1</i>&nbsp;package nl.tudelft.jpacman.board;
<i class="no-highlight">2</i>&nbsp;
<i class="no-highlight">3</i>&nbsp;import java.util.ArrayList;
<i class="no-highlight">4</i>&nbsp;import java.util.EnumMap;
<i class="no-highlight">5</i>&nbsp;import java.util.List;
<i class="no-highlight">6</i>&nbsp;import java.util.Map;
<i class="no-highlight">7</i>&nbsp;
<i class="no-highlight">8</i>&nbsp;import com.google.common.collect.ImmutableList;
<i class="no-highlight">9</i>&nbsp;
<i class="no-highlight">10</i>&nbsp;import nl.tudelft.jpacman.sprite.Sprite;
<i class="no-highlight">11</i>&nbsp;/**
<i class="no-highlight">12</i>&nbsp; * A square on a {@link Board}, which can (or cannot, depending on the type) be
<i class="no-highlight">13</i>&nbsp; * occupied by units.
<i class="no-highlight">14</i>&nbsp; *
<i class="no-highlight">15</i>&nbsp; * @author Jeroen Roosen 
<i class="no-highlight">16</i>&nbsp; */
<b class="fc"><i class="no-highlight">17</i>&nbsp;public abstract class Square {</b>
<i class="no-highlight">18</i>&nbsp;
<i class="no-highlight">19</i>&nbsp;    /**
<i class="no-highlight">20</i>&nbsp;     * The units occupying this square, in order of appearance.
<i class="no-highlight">21</i>&nbsp;     */
<i class="no-highlight">22</i>&nbsp;    private final List&lt;Unit&gt; occupants;
<i class="no-highlight">23</i>&nbsp;
<i class="no-highlight">24</i>&nbsp;    /**
<i class="no-highlight">25</i>&nbsp;     * The collection of squares adjacent to this square.
<i class="no-highlight">26</i>&nbsp;     */
<i class="no-highlight">27</i>&nbsp;    private final Map&lt;Direction, Square&gt; neighbours;
<i class="no-highlight">28</i>&nbsp;
<i class="no-highlight">29</i>&nbsp;    /**
<i class="no-highlight">30</i>&nbsp;     * Creates a new, empty square.
<i class="no-highlight">31</i>&nbsp;     */
<b class="nc"><i class="no-highlight">32</i>&nbsp;    protected Square() {</b>
<b class="nc"><i class="no-highlight">33</i>&nbsp;        this.occupants = new ArrayList&lt;&gt;();</b>
<b class="nc"><i class="no-highlight">34</i>&nbsp;        this.neighbours = new EnumMap&lt;&gt;(Direction.class);</b>
<b class="nc"><i class="no-highlight">35</i>&nbsp;        assert invariant();</b>
<b class="nc"><i class="no-highlight">36</i>&nbsp;    }</b>
<i class="no-highlight">37</i>&nbsp;
<i class="no-highlight">38</i>&nbsp;    /**
<i class="no-highlight">39</i>&nbsp;     * Returns the square adjacent to this square.
<i class="no-highlight">40</i>&nbsp;     *
<i class="no-highlight">41</i>&nbsp;     * @param direction
<i class="no-highlight">42</i>&nbsp;     *            The direction of the adjacent square.
<i class="no-highlight">43</i>&nbsp;     * @return The adjacent square in the given direction.
<i class="no-highlight">44</i>&nbsp;     */
<i class="no-highlight">45</i>&nbsp;    public Square getSquareAt(Direction direction) {
<b class="nc"><i class="no-highlight">46</i>&nbsp;        return neighbours.get(direction);</b>
<i class="no-highlight">47</i>&nbsp;    }
<i class="no-highlight">48</i>&nbsp;
<i class="no-highlight">49</i>&nbsp;    /**
<i class="no-highlight">50</i>&nbsp;     * Links this square to a neighbour in the given direction. Note that this
<i class="no-highlight">51</i>&nbsp;     * is a one-way connection.
<i class="no-highlight">52</i>&nbsp;     *
<i class="no-highlight">53</i>&nbsp;     * @param neighbour
<i class="no-highlight">54</i>&nbsp;     *            The neighbour to link.
<i class="no-highlight">55</i>&nbsp;     * @param direction
<i class="no-highlight">56</i>&nbsp;     *            The direction the new neighbour is in, as seen from this cell.
<i class="no-highlight">57</i>&nbsp;     */
<i class="no-highlight">58</i>&nbsp;    public void link(Square neighbour, Direction direction) {
<b class="nc"><i class="no-highlight">59</i>&nbsp;        neighbours.put(direction, neighbour);</b>
<b class="nc"><i class="no-highlight">60</i>&nbsp;        assert invariant();</b>
<b class="nc"><i class="no-highlight">61</i>&nbsp;    }</b>
<i class="no-highlight">62</i>&nbsp;
<i class="no-highlight">63</i>&nbsp;    /**
<i class="no-highlight">64</i>&nbsp;     * Returns an immutable list of units occupying this square, in the order in
<i class="no-highlight">65</i>&nbsp;     * which they occupied this square (i.e. oldest first.)
<i class="no-highlight">66</i>&nbsp;     *
<i class="no-highlight">67</i>&nbsp;     * @return An immutable list of units occupying this square, in the order in
<i class="no-highlight">68</i>&nbsp;     *         which they occupied this square (i.e. oldest first.)
<i class="no-highlight">69</i>&nbsp;     */
<i class="no-highlight">70</i>&nbsp;    public List&lt;Unit&gt; getOccupants() {
<b class="nc"><i class="no-highlight">71</i>&nbsp;        return ImmutableList.copyOf(occupants);</b>
<i class="no-highlight">72</i>&nbsp;    }
<i class="no-highlight">73</i>&nbsp;
<i class="no-highlight">74</i>&nbsp;    /**
<i class="no-highlight">75</i>&nbsp;     * Adds a new occupant to this square.
<i class="no-highlight">76</i>&nbsp;     *
<i class="no-highlight">77</i>&nbsp;     * @param occupant
<i class="no-highlight">78</i>&nbsp;     *            The unit to occupy this square.
<i class="no-highlight">79</i>&nbsp;     */
<i class="no-highlight">80</i>&nbsp;    void put(Unit occupant) {
<b class="nc"><i class="no-highlight">81</i>&nbsp;        assert occupant != null;</b>
<b class="nc"><i class="no-highlight">82</i>&nbsp;        assert !occupants.contains(occupant);</b>
<i class="no-highlight">83</i>&nbsp;
<b class="nc"><i class="no-highlight">84</i>&nbsp;        occupants.add(occupant);</b>
<b class="nc"><i class="no-highlight">85</i>&nbsp;    }</b>
<i class="no-highlight">86</i>&nbsp;
<i class="no-highlight">87</i>&nbsp;    /**
<i class="no-highlight">88</i>&nbsp;     * Removes the unit from this square if it was present.
<i class="no-highlight">89</i>&nbsp;     *
<i class="no-highlight">90</i>&nbsp;     * @param occupant
<i class="no-highlight">91</i>&nbsp;     *            The unit to be removed from this square.
<i class="no-highlight">92</i>&nbsp;     */
<i class="no-highlight">93</i>&nbsp;    void remove(Unit occupant) {
<b class="nc"><i class="no-highlight">94</i>&nbsp;        assert occupant != null;</b>
<b class="nc"><i class="no-highlight">95</i>&nbsp;        occupants.remove(occupant);</b>
<b class="nc"><i class="no-highlight">96</i>&nbsp;    }</b>
<i class="no-highlight">97</i>&nbsp;
<i class="no-highlight">98</i>&nbsp;    /**
<i class="no-highlight">99</i>&nbsp;     * Verifies that all occupants on this square have indeed listed this square
<i class="no-highlight">100</i>&nbsp;     * as the square they are currently occupying.
<i class="no-highlight">101</i>&nbsp;     *
<i class="no-highlight">102</i>&nbsp;     * @return &lt;code&gt;true&lt;/code&gt; iff all occupants of this square have this
<i class="no-highlight">103</i>&nbsp;     *         square listed as the square they are currently occupying.
<i class="no-highlight">104</i>&nbsp;     */
<i class="no-highlight">105</i>&nbsp;    protected final boolean invariant(Square this) {
<b class="nc"><i class="no-highlight">106</i>&nbsp;        for (Unit occupant : occupants) {</b>
<b class="nc"><i class="no-highlight">107</i>&nbsp;            if (occupant.hasSquare() &amp;&amp; occupant.getSquare() != this) {</b>
<b class="nc"><i class="no-highlight">108</i>&nbsp;                return false;</b>
<i class="no-highlight">109</i>&nbsp;            }
<b class="nc"><i class="no-highlight">110</i>&nbsp;        }</b>
<b class="nc"><i class="no-highlight">111</i>&nbsp;        return true;</b>
<i class="no-highlight">112</i>&nbsp;    }
<i class="no-highlight">113</i>&nbsp;
<i class="no-highlight">114</i>&nbsp;    /**
<i class="no-highlight">115</i>&nbsp;     * Determines whether the unit is allowed to occupy this square.
<i class="no-highlight">116</i>&nbsp;     *
<i class="no-highlight">117</i>&nbsp;     * @param unit
<i class="no-highlight">118</i>&nbsp;     *            The unit to grant or deny access.
<i class="no-highlight">119</i>&nbsp;     * @return &lt;code&gt;true&lt;/code&gt; iff the unit is allowed to occupy this square.
<i class="no-highlight">120</i>&nbsp;     */
<i class="no-highlight">121</i>&nbsp;    public abstract boolean isAccessibleTo(Unit unit);
<i class="no-highlight">122</i>&nbsp;
<i class="no-highlight">123</i>&nbsp;    /**
<i class="no-highlight">124</i>&nbsp;     * Returns the sprite of this square.
<i class="no-highlight">125</i>&nbsp;     *
<i class="no-highlight">126</i>&nbsp;     * @return The sprite of this square.
<i class="no-highlight">127</i>&nbsp;     */
<i class="no-highlight">128</i>&nbsp;    public abstract Sprite getSprite();
<i class="no-highlight">129</i>&nbsp;
<i class="no-highlight">130</i>&nbsp;}
</div>
</pre>
</div>

<script type="text/javascript">
(function() {
    var msie = false, msie9 = false;
    /*@cc_on
      msie = true;
      @if (@_jscript_version >= 9)
        msie9 = true;
      @end
    @*/

    if (!msie || msie && msie9) {
        var codeBlock = document.getElementById('sourceCode');

        if (codeBlock) {
            hljs.highlightBlock(codeBlock);
        }
    }
})();
</script>

<div class="footer">
    
    <div style="float:right;">generated on 2022-05-22 18:55</div>
</div>
</body>
</html>
